/**
* 发票详情对话框（可用于添加和修改对话框）
*/
var InvoiceInfoDlg = {
    width: '650px',
    height: '800px',
    currentLayerIndex: -1,
    cache: "",
    InfoData: {}
};

/**
 * 初始化新增弹出框
 */
InvoiceInfoDlg.init = function () {
    this.cache = $("#invoiceDialog").html();
    $("#invoiceDialog").html('');
};

/**
 * 清除数据
 */
InvoiceInfoDlg.clearData = function () {
    this.InfoData = {};
};

/**
 * 关闭此对话框
 */
InvoiceInfoDlg.close = function () {
    layer.close(this.currentLayerIndex);
};

/**
 * 新增打开模态框调用事件
 */
InvoiceInfoDlg.renderAdd = function (index) {
    //初始化icheck选中样式
    initICheck();

};


/**
 * 编辑
 */
InvoiceInfoDlg.load = function (id) {
    var ajax = new $ax(Feng.ctxPath+"/invoice/getById", function(data){
        Feng.log("发票信息查询成功");
        if (data.success){
            var invoice = data.obj || null;
            for (var i in invoice){
                //判断Id与name是否相同
                if($("#"+i).attr("name")==i){
                    if(i=="orderNum"||i=="applyDate" || i== "invoiceSerialNumber"){
                        $("#" + i).html(invoice[i]||"无");
                    }else{
                        $("#"+i).val(invoice[i]);
                    }
                }
            }
            //状态判断
            if(invoice.applyStatus == 1){
                $("#applyStatus").html("申请中");
            }else if(invoice.applyStatus == 2){
                $("#applyStatus").html("已办理");
            }else{
                //隐藏编辑按钮
                $(".layui-layer-btn0").hide();
                $("#applyStatus").html("已作废");
            }


            //发票类型
            if(invoice.invoiceType == 1){
                $("#invoiceType").html("个人");
                $("#taxCodeDiv").css("display","none");
                $("#unitAddressDiv").css("display","none");
                $("#bankDiv").css("display","none");
                $("#bankAccountDiv").css("display","none");

            }else if(invoice.invoiceType == 2){
                $("#invoiceType").html("公司");
            }

            //金额显示
            $("#orderPrice").html(numeral(invoice.orderPrice).format('0,0.00'));

        }
    },function(data){
        Feng.error("加载信息失败!");
    });
    ajax.data={id:id};
    ajax.start();
};


/**
 * 修改发票申请
 */
InvoiceInfoDlg.editSubmit = function () {

    this.clearData();
    this.InfoData = getFormJson("#frmMain");
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/invoice/update", function (data) {
        Feng.success("发票修改成功!");
        InvoiceTable.me.refresh();
    }, function (data) {
        Feng.error("发票修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.InfoData);
    ajax.start();
};
